package common;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Random;

public class ImgUtil {

	public static String STR="abcdefghijkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY3456789";
	public static int LEN=4;
	public static int WIDTH=15;
	public static int HEIGHT=30;
	public static int SPAN=4;
	public static int IMGWIDTH=(WIDTH+SPAN)*LEN;
	

	public static char[] getStr() {
		char[] result=new char[LEN];
		for (int i = 0; i < LEN; i++) {
			Random random=new Random();
			result[i]=STR.charAt(random.nextInt(STR.length()));
		}
		return result;
	}
	public static BufferedImage getImage(char[] array) {

		BufferedImage img=new BufferedImage(IMGWIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);

		Graphics graphics=img.getGraphics();

		graphics.setColor(Color.gray);

		graphics.fillRect(0, 0, IMGWIDTH, HEIGHT);

		Font font=new Font("楷体",Font.BOLD , 16);
		graphics.setFont(font);

		graphics.setColor(Color.WHITE);
		for (int i = 0; i < array.length; i++) {
			graphics.drawString(String.valueOf(array[i]), (WIDTH+SPAN)*i, HEIGHT-10);
		}
		return img;
	}
	
}
